"use strict"
//将方法序列化
var xiaoming = {
    name: '小明',
    age: 36,
    height: 185,
    grade: null,
    'middle-school': '\"W3C\" Middle School',
    skills: ['JavaScript', 'Java', 'Python', 'Lisp']
}

var s = JSON.stringify(xiaoming, null, " ");
console.log(s);

//将字符串全部大写
function count(key, value) {
    if (typeof value === 'string') {
        return value.toUpperCase();
    }
    return value;
}
var a = JSON.stringify(xiaoming, count, " ");
console.log(a);

//直接返回JSON应该序列化的数据
var xiaomin = {
        name: '小明',
        age: 36,
        height: 185,
        grade: null,
        'middle-school': '\"W3C\" Middle School',
        skills: ['JavaScript', 'Java', 'Python', 'Lisp'],
        toJSON: function() {
            return {
                name: this.name,
                age: this.age
            }
        }
    }
    //JSON.stringify(xiaoming); // '{"Name":"小明","Age":14}' 反序列化 
    //拿到一个JSON格式的字符串，我们直接用JSON.parse()把它变成一个JavaScript对象：
console.log(JSON.parse('{"name":"小明","age":14}'));
"use strict"
var obj = JSON.parse(('{"name":"小明","age":14}'), function(key, value) {
    if (key === 'name') {
        return value + "同志"
    }
    return value;
})
console.log(JSON.stringify(obj));

//面向对象
var Student = {
    name: "Root",
    height: 160,
    fly: function() {
        console.log(this.name + "ius,love");
    }
}

var xiaomin = {
    name: "陈璐萍"
}
xiaomin._prototype_ = Student;

console.log(xiaomin.name);

//构造函数

// function Students(name) {
//     this.name = name,
//         this.Hello = function() {
//             console.log("Hello," + this.name + "!");
//         }

// }
// var xiaohong = new Students("小红")

// console.log(xiaohong.Hello());

//createStudent()函数
"use strict"

function Students(props) {
    this.name = props.name || "匿名",
        this.grade = props.grade || 1
}
Students.prototype.Hello = function() {
    console.log("hello," + this.name + "!");
}

function createStudent(props) {
    return new Students(props || {})
}

var xiaozhang = createStudent({
    name: "小长"
})

console.log(xiaozhang.grade);

//class
"use strict"
class Stu {
    constructor(name) {
        this.name = name
    }
    hello() {
        console.log("hello," + this.name + "!");
    }
}
class PrimaryStudent extends Student {
    constructor(name, grade) {
        super(name); // 记得用super调用父类的构造方法!
        this.grade = grade;
    }

    myGrade() {
        alert('I am at grade ' + this.grade);
    }
}